<template>
  <div class="app-container">
    <div class="filter-container">
      <el-input v-model="listQuery.consignee" clearable class="filter-item" style="width: 200px;" placeholder="收货人姓名"/>
      <el-button v-permission="['address:list']" class="filter-item" type="primary" icon="el-icon-search" @click="handleFilter">查找</el-button>
    </div>

    <el-table v-loading="listLoading" :data="list" size="small" element-loading-text="正在查询中..." border fit highlight-current-row>
      <el-table-column align="center" label="地址ID" width="80" prop="id" />
      <el-table-column align="center" label="用户昵称" width="80" prop="nickName" />
      <el-table-column align="center" label="签收人" prop="consignee" />
      <el-table-column align="center" label="手机号" prop="phone" />
      <el-table-column align="center" label="省份" prop="province" />
      <el-table-column align="center" label="城市" prop="city" />
      <el-table-column align="center" label="区/县" prop="district" />
      <el-table-column align="center" label="详情地址" prop="address" />
    </el-table>
    <pagination v-permission="['address:list']" v-show="total>0" :total="total" :page.sync="listQuery.pageNo" :limit.sync="listQuery.pageSize" @pagination="initList"/>
  </div>
</template>

<script>
import { UserService } from '@/api/UserService'
import Pagination from '@/components/Pagination'

export default {
  name: 'Address',
  components: { Pagination },
  data() {
    return {
      list: [],
      total: 0,
      listLoading: true,
      listQuery: {
        pageNo: 1,
        pageSize: 20,
        consignee: undefined
      }
    }
  },
  created() {
    this.initList()
  },
  methods: {
    initList() {
      this.listLoading = true
      UserService.listAddress(this.listQuery).then(response => {
        this.list = response.data
        this.total = response.totalCount
        this.listLoading = false
      })
    },
    handleFilter() {
      this.listQuery.pageNo = 1
      this.initList()
    }
  }
}
</script>
